/* GUI CONVERTED from cscscpb.p (converter v1.76) Tue Apr 23 11:41:37 2002 */
/* cscscpb.p - SIMULATION TO SIMULATION COPY                              */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                    */
/* All rights reserved worldwide.  This is an unpublished work.           */
/* $Revision: 1.12.1.9 $                                                       */
/*V8:ConvertMode=Report                                                   */
/* REVISION: 7.0     LAST MODIFIED: 08/28/91    BY: pma *F003*            */
/* REVISION: 7.3     LAST MODIFIED: 02/05/93    BY: pma *G032*            */
/*                                  10/12/93    BY: jzs *GG27*            */
/* REVISION: 7.3     LAST MODIFIED: 11/17/93    BY: ais *GH31*            */
/* REVISION: 7.3     LAST MODIFIED: 09/11/94    BY: slm *GM33*            */
/* REVISION: 7.3     LAST MODIFIED: 10/27/94    BY: ame *GN64*            */
/* REVISION: 7.3     LAST MODIFIED: 12/27/94    BY: jwy *F0BV*            */
/* REVISION: 7.3     LAST MODIFIED: 01/03/95    BY: ame *F0CJ*            */
/* REVISION: 7.3     LAST MODIFIED: 07/31/95    BY: ais *G0T2*            */
/* REVISION: 8.5     LAST MODIFIED: 08/21/95    BY: wep *J054*            */
/* REVISION: 7.3     LAST MODIFIED: 01/29/96    BY: bcm *G1LK*            */
/* REVISION: 8.6E    LAST MODIFIED: 02/23/98    BY: *L007* A. Rahane      */
/* REVISION: 8.6E    LAST MODIFIED: 03/10/98    BY: *J29Z* Kawal Batra    */
/* REVISION: 8.6E    LAST MODIFIED: 04/13/98    BY: *J2K4* Kawal Batra    */
/* REVISION: 8.6E    LAST MODIFIED: 05/20/98    BY: *K1Q4* Alfred Tan     */
/* REVISION: 8.6E    LAST MODIFIED: 10/04/98    BY: *J314* Alfred Tan     */
/* REVISION: 9.1     LAST MODIFIED: 03/24/00    BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1     LAST MODIFIED: 08/11/00    BY: *N0KK* jyn                */
/* REVISION: 9.1     LAST MODIFIED: 08/23/00    BY: *N0MW* BalbeerS Rajput    */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.12.1.7     BY: Katie Hilbert         DATE: 02/25/02  ECO: *N194*  */
/* $Revision: 1.12.1.9 $    BY: Samir Bavkar         DATE: 04/12/02  ECO: *P000*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdeclre.i}
{gplabel.i} /* EXTERNAL LABEL INCLUDE */

define shared variable transtype as character.
define shared variable site  like si_site.
define shared variable site1 like si_site.
define shared variable part  like sct_part.
define shared variable part1 like sct_part.
define shared variable line  like pt_prod_line.
define shared variable line1 like pt_prod_line.
define shared variable type  like pt_part_type.
define shared variable type1 like pt_part_type.
define shared variable clss  like pt_abc.
define shared variable clss1 like pt_abc.
define shared variable pmcd  like pt_pm_code.
define shared variable pmcd1 like pt_pm_code.
define shared variable ptgp  like pt_group.
define shared variable ptgp1 like pt_group.
define shared variable ptby  like pt_buyer.
define shared variable ptby1 like pt_buyer.
define shared variable toset like sct_sim.
define shared variable fromset like sct_sim.

define shared variable postol as decimal format ">>>9.9%".
define shared variable negtol as decimal format ">9.9%".
define shared variable mtl_flag as logical initial yes
   label "Copy Material Cost".
define shared variable lbr_flag as logical initial yes
   label "Copy Labor Cost".
define shared variable bdn_flag as logical initial yes
   label "Copy Burden Cost".
define shared variable ovh_flag as logical initial yes
   label "Copy Overhead Cost".
define shared variable sub_flag as logical initial yes
   label "Copy Subcontract Cost".

define variable oldcst like sct_cst_tot no-undo.
define variable tocsgl as logical.
define variable tot_pct as decimal format "->>>,>>9.9 %".
define variable mtl_pct like tot_pct.
define variable lbr_pct like tot_pct.
define variable bdn_pct like tot_pct.
define variable ovh_pct like tot_pct.
define variable sub_pct like tot_pct.
define variable cntr as integer format "9" no-undo.
define variable rndmthd like gl_rnd_mthd no-undo.

define buffer setfr for sct_det.
define buffer oldto for sct_det.
define buffer sptdet for spt_det.
define workfile newto like sct_det.


define workfile newspt like spt_det
   field category like sc_mstr.sc_category.

define temp-table ttptp_det
   field ptp_buyer   like ptp_buyer
   field ptp_part    like ptp_part
   field ptp_pm_code like ptp_pm_code
   index ptp_part ptp_part.

for each ptp_det
   fields(ptp_buyer ptp_part ptp_pm_code ptp_site)
   where ptp_site = site no-lock:

   create ttptp_det.
   buffer-copy ptp_det to ttptp_det.
end.

define temp-table ttin_mstr
   field in_gl_set       like in_gl_set
   field in_part         like in_part
   field in_cur_set      like in_cur_set
   field in_site         like in_site
   field in_gl_cost_site like in_gl_cost_site
   index in_part in_part.

for each in_mstr
   fields(in_gl_set in_part in_cur_set in_site in_gl_cost_site)
   where in_site = site1 no-lock:

   create ttin_mstr.
   buffer-copy in_mstr to ttin_mstr.
end.

define temp-table ttsc_mstr like sc_mstr.

for each sc_mstr no-lock:
   create ttsc_mstr.
   buffer-copy sc_mstr to ttsc_mstr.
end.

define buffer scmstr for ttsc_mstr.
define buffer del-spt_det for spt_det.

for first gl_ctrl fields(gl_rnd_mthd) no-lock:
end.
if available gl_ctrl then rndmthd = gl_rnd_mthd.

for first si_mstr fields(si_site si_cur_set si_gl_set)
   where si_site = site1
no-lock:
end.

assign
   glxcst = 0
   curcst = 100000
   tocsgl = no.

for first icc_ctrl
   fields(icc_gl_set icc_cogs icc_gl_sum
          icc_gl_tran icc_mirror icc_jrnl)
no-lock:
end.

FORM /*GUI*/  header
   skip(1)
with STREAM-IO /*GUI*/  frame p1 page-top width 132.

view frame p1.

if icc_gl_set = toset
   or can-find(cs_mstr where cs_set = toset and cs_type = "GL")
then
   tocsgl = yes.

copyloop:

for each setfr
   fields(sct_bdn_ll sct_bdn_tl sct_cst_date sct_cst_tot
          sct_lbr_ll sct_lbr_tl sct_mtl_ll sct_mtl_tl
          sct_ovh_ll sct_ovh_tl sct_part sct_sim sct_site
          sct_sub_ll sct_sub_tl sct_user1 sct_user2) no-lock
   use-index sct_sim_pt_site
   where setfr.sct_sim = fromset
    and (setfr.sct_part >= part and setfr.sct_part <= part1)
    and  setfr.sct_site = site,

    each pt_mstr
       fields(pt_abc pt_buyer pt_desc1 pt_desc2 pt_group pt_site
              pt_part pt_part_type pt_pm_code pt_prod_line pt_um)
      where (pt_part = setfr.sct_part)
        and (pt_prod_line >= line and pt_prod_line <= line1)
        and (pt_part_type >= type and pt_part_type <= type1)
        and (pt_group >= ptgp and pt_group <= ptgp1)
        and (pt_abc >= clss and pt_abc <= clss1)
   no-lock
   with frame b width 132 no-box:
   /* SET EXTERNAL LABELS */
   setFrameLabels(frame b:handle).
   
/* fdn 2006.04.30 del begin *******************************************   
/*Add by tony*/
   if (transtype = "CS01" /* cost set copy to cost set  */
     and setfr.sct_cst_tot = 0 )  /*Not copy zero data*/
   then next copyloop.
/*end by tony*/
** fdn 2006.04.30 del begin *******************************************/


   find first ttptp_det where ttptp_det.ptp_part = pt_part
   no-lock no-error.

   if (available ttptp_det and
      (ttptp_det.ptp_pm_code < pmcd or ttptp_det.ptp_pm_code > pmcd1 or
       ttptp_det.ptp_buyer < ptby   or ttptp_det.ptp_buyer > ptby1)) or
      (not available ttptp_det and
      (pt_pm_code < pmcd or pt_pm_code > pmcd1  or
       pt_buyer < ptby   or pt_buyer > ptby1))
   then next.

   /* CURRENT COST SET MOVE TO GL SET  (1.4.22) AND                 */
   /* GL COST SET MOVE TO CURRENT SET (1.4.23) USE ACTIVE COST SETS.*/
   /* FOR LINKED TARGET SITES (SITE-ITEM LINKED TO SOURCE SITE) THE */
   /* GL COSTS AT THAT SITE ARE NOT ACTIVE.                         */
   /* THEREFORE WE WILL NOT MOVE GL COSTS FROM or TO LINKED TARGET  */
   /* SITES.                                                        */
   /* FOR THESE MENU ITEMS FROM (site) AND TO SITE (site1) ARE SAME.*/

   if (transtype = "PP01" /* FROM CURRENT to GL */
      or transtype = "PP02") /* FROM GL to CURRENT */
   and (can-find(first in_mstr where in_part = sct_part
                                 and in_site = site1
                                 and in_site <> in_gl_cost_site))
   then next copyloop.


   for each newto exclusive-lock:
      delete newto.
   end.

   for each newspt exclusive-lock:
      delete newspt.
   end.

   create newto.
   assign
      newto.sct_sim  = toset
      newto.sct_part = pt_part
      newto.sct_site = site.

   for each spt_det
      fields(spt_ao spt_cst_ll spt_cst_tl spt_element
             spt_mod_date spt_part spt_pct_ll spt_pct_tl
             spt_sim spt_site spt_user1 spt_user2 spt_userid)
         where spt_site = site
           and spt_sim  = fromset
           and spt_part = pt_part no-lock:
      if integer(spt_det.spt_pct_ll) < 1 or
         integer(spt_det.spt_pct_ll) > 5
      then
         next copyloop.
      if (mtl_flag and integer(spt_det.spt_pct_ll) = 1) or
         (lbr_flag and integer(spt_det.spt_pct_ll) = 2) or
         (bdn_flag and integer(spt_det.spt_pct_ll) = 3) or
         (ovh_flag and integer(spt_det.spt_pct_ll) = 4) or
         (sub_flag and integer(spt_det.spt_pct_ll) = 5)
      then do:

         /* CHECK FOR CATEGORY MISMATCH                    */

         find ttsc_mstr where ttsc_mstr.sc_sim = toset
            and ttsc_mstr.sc_element = spt_det.spt_element
         no-lock no-error.

         if available ttsc_mstr then
            if ttsc_mstr.sc_category <> string(integer(spt_pct_ll))
            then next copyloop.

         find first newspt
            where newspt.spt_element = spt_det.spt_element
            no-error.
         if available newspt then next copyloop.

         create newspt.
         assign
            newspt.spt_site     = site1
            newspt.spt_sim      = toset
            newspt.spt_part     = spt_part
            newspt.spt_element  = spt_element
            newspt.spt_ao       = spt_ao
            newspt.spt_cst_ll   = spt_cst_ll
            newspt.spt_cst_tl   = spt_cst_tl
            newspt.spt_element  = spt_element
            newspt.spt_mod_date = today
            newspt.spt_pct_ll   = spt_pct_ll
            newspt.spt_pct_tl   = spt_pct_tl
            newspt.spt_userid   = spt_userid
            newspt.category     = string(integer(spt_pct_ll))
            newspt.spt_user1    = spt_user1
            newspt.spt_user2    = spt_user2.

      end.
   end.   /*FROM SET*/

   for each spt_det
      fields(spt_ao spt_cst_ll spt_cst_tl spt_element
             spt_mod_date spt_part spt_pct_ll spt_pct_tl
             spt_sim spt_site spt_user1 spt_user2 spt_userid)
         where spt_site = site1
           and spt_sim  = toset
           and spt_part = pt_part no-lock:
      if integer(spt_det.spt_pct_ll) < 1 or
         integer(spt_det.spt_pct_ll) > 5
      then next copyloop.
      if ((not mtl_flag) and integer(spt_det.spt_pct_ll) = 1)
      or ((not lbr_flag) and integer(spt_det.spt_pct_ll) = 2)
      or ((not bdn_flag) and integer(spt_det.spt_pct_ll) = 3)
      or ((not ovh_flag) and integer(spt_det.spt_pct_ll) = 4)
      or ((not sub_flag) and integer(spt_det.spt_pct_ll) = 5)
      then do:

         find first newspt
            where newspt.spt_element = spt_det.spt_element
            no-error.
         if available newspt then next copyloop.

         create newspt.
         assign
            newspt.spt_site     = site1
            newspt.spt_sim      = toset
            newspt.spt_part     = spt_part
            newspt.spt_element  = spt_element
            newspt.spt_ao       = spt_ao
            newspt.spt_cst_ll   = spt_cst_ll
            newspt.spt_cst_tl   = spt_cst_tl
            newspt.spt_element  = spt_element
            newspt.spt_mod_date = spt_mod_date
            newspt.spt_pct_ll   = spt_pct_ll
            newspt.spt_pct_tl   = spt_pct_tl
            newspt.spt_userid   = spt_userid
            newspt.category     = string(integer(spt_pct_ll))
            newspt.spt_user1    = spt_user1
            newspt.spt_user2    = spt_user2.
      end.
   end.   /*TO SET*/

   for each newspt exclusive-lock break by newspt.category:
      /*  VERIFY EACH CATEGORY HAS 1 and ONLY 1 PRIMARY */
      if first-of(category) then assign cntr = 0.
      if integer(newspt.spt_pct_ll) = newspt.spt_pct_ll
      then
         cntr = cntr + 1.
      if last-of(category) and cntr <> 1
      then next copyloop.

      if integer(newspt.spt_pct_ll) = 1 then do:

         assign
            newto.sct_mtl_tl = newto.sct_mtl_tl + newspt.spt_cst_tl
            newto.sct_mtl_ll = newto.sct_mtl_ll + newspt.spt_cst_ll.

      end.
      else if integer(newspt.spt_pct_ll) = 2 then

         assign
            newto.sct_lbr_tl = newto.sct_lbr_tl + newspt.spt_cst_tl
            newto.sct_lbr_ll = newto.sct_lbr_ll + newspt.spt_cst_ll.

      else if integer(newspt.spt_pct_ll) = 3 then

         assign
            newto.sct_bdn_tl = newto.sct_bdn_tl + newspt.spt_cst_tl
            newto.sct_bdn_ll = newto.sct_bdn_ll + newspt.spt_cst_ll.

      else if integer(newspt.spt_pct_ll) = 4 then

         assign
            newto.sct_ovh_tl = newto.sct_ovh_tl + newspt.spt_cst_tl
            newto.sct_ovh_ll = newto.sct_ovh_ll + newspt.spt_cst_ll.

      else if integer(newspt.spt_pct_ll) = 5 then

         assign
            newto.sct_sub_tl = newto.sct_sub_tl + newspt.spt_cst_tl
            newto.sct_sub_ll = newto.sct_sub_ll + newspt.spt_cst_ll.

      else delete newspt.

   end.  /* newspt */

   assign
      newto.sct_cst_tot =   newto.sct_mtl_tl + newto.sct_mtl_ll
                          + newto.sct_lbr_tl + newto.sct_lbr_ll
                          + newto.sct_bdn_tl + newto.sct_bdn_ll
                          + newto.sct_ovh_tl + newto.sct_ovh_ll
                          + newto.sct_sub_tl + newto.sct_sub_ll

      mtl_pct = 0
      lbr_pct = 0
      bdn_pct = 0
      ovh_pct = 0
      sub_pct = 0
      tot_pct = 0 .

   for first oldto
      fields(sct_bdn_ll sct_bdn_tl sct_cst_date sct_cst_tot
             sct_lbr_ll sct_lbr_tl sct_mtl_ll sct_mtl_tl
             sct_ovh_ll sct_ovh_tl sct_part sct_sim sct_site
             sct_sub_ll sct_sub_tl sct_user1 sct_user2)
   no-lock
   where oldto.sct_sim = toset
     and oldto.sct_part = pt_part
     and oldto.sct_site = site1:
   end.
   
  /*fdn* 2006.04.30 ****************************** begin **********/
   if ( setfr.sct_cst_tot = 0 ) and ( available oldto ) then
       next copyloop.
   /*fdn* 2006.04.30 *****************************  end  **********/
   
   if available oldto then
      assign
         tot_pct = 100 * (newto.sct_cst_tot - oldto.sct_cst_tot)
                 / oldto.sct_cst_tot.
   else
      assign tot_pct = ?.

   if (negtol = 0 and postol = 0 and tot_pct = ?)
   or (negtol <> ? and tot_pct < negtol)
   or (postol <> ? and tot_pct > postol)
   then
      next copyloop.

   find first oldto exclusive-lock where oldto.sct_sim = toset
      and oldto.sct_part = pt_part
      and oldto.sct_site = site1 no-error.
   if not available oldto then do:
      create oldto.
      assign
         oldto.sct_sim = toset
         oldto.sct_part = pt_part
         oldto.sct_site = site1.
   end. /* if not available oldto */

   assign
      mtl_pct = 100 * ((newto.sct_mtl_tl + newto.sct_mtl_ll)
                    -  (oldto.sct_mtl_tl + oldto.sct_mtl_ll))
                    /  (oldto.sct_mtl_tl + oldto.sct_mtl_ll)
      lbr_pct = 100 * ((newto.sct_lbr_tl + newto.sct_lbr_ll)
                    -  (oldto.sct_lbr_tl + oldto.sct_lbr_ll))
                    /  (oldto.sct_lbr_tl + oldto.sct_lbr_ll)
      bdn_pct = 100 * ((newto.sct_bdn_tl + newto.sct_bdn_ll)
                    -  (oldto.sct_bdn_tl + oldto.sct_bdn_ll))
                    /  (oldto.sct_bdn_tl + oldto.sct_bdn_ll)
      ovh_pct = 100 * ((newto.sct_ovh_tl + newto.sct_ovh_ll)
                    -  (oldto.sct_ovh_tl + oldto.sct_ovh_ll))
                    /  (oldto.sct_ovh_tl + oldto.sct_ovh_ll)
      sub_pct = 100 * ((newto.sct_sub_tl + newto.sct_sub_ll)
                    -  (oldto.sct_sub_tl + oldto.sct_sub_ll))
                    /  (oldto.sct_sub_tl + oldto.sct_sub_ll).

   display
      pt_part
      pt_um
      fromset no-label
      setfr.sct_mtl_tl + setfr.sct_mtl_ll @ setfr.sct_mtl_tl
      format "->>,>>>,>>9.99<<<"
      setfr.sct_lbr_tl + setfr.sct_lbr_ll @ setfr.sct_lbr_tl
      format "->>,>>>,>>9.99<<<"
      setfr.sct_bdn_tl + setfr.sct_bdn_ll @ setfr.sct_bdn_tl
      format "->>,>>>,>>9.99<<<"
      setfr.sct_ovh_tl + setfr.sct_ovh_ll @ setfr.sct_ovh_tl
      format "->>,>>>,>>9.99<<<"
      setfr.sct_sub_tl + setfr.sct_sub_ll @ setfr.sct_sub_tl
      format "->>,>>>,>>9.99<<<"
      setfr.sct_cst_tot @ setfr.sct_cst_tot
      format "->>>,>>>,>>9.99<<<" WITH STREAM-IO /*GUI*/ .
   down 1.
   display
      pt_desc1 format "x(18)" @ pt_part
      toset @ fromset
      oldto.sct_mtl_tl + oldto.sct_mtl_ll @ setfr.sct_mtl_tl
      oldto.sct_lbr_tl + oldto.sct_lbr_ll @ setfr.sct_lbr_tl
      oldto.sct_bdn_tl + oldto.sct_bdn_ll @ setfr.sct_bdn_tl
      oldto.sct_ovh_tl + oldto.sct_ovh_ll @ setfr.sct_ovh_tl
      oldto.sct_sub_tl + oldto.sct_sub_ll @ setfr.sct_sub_tl
      oldto.sct_cst_tot @ setfr.sct_cst_tot WITH STREAM-IO /*GUI*/ .
   down 1.
   display
      pt_desc2 format "x(18)" @ pt_part
      getTermLabel("NEW_COST",8) @ fromset
      newto.sct_mtl_tl + newto.sct_mtl_ll @ setfr.sct_mtl_tl
      newto.sct_lbr_tl + newto.sct_lbr_ll @ setfr.sct_lbr_tl
      newto.sct_bdn_tl + newto.sct_bdn_ll @ setfr.sct_bdn_tl
      newto.sct_ovh_tl + newto.sct_ovh_ll @ setfr.sct_ovh_tl
      newto.sct_sub_tl + newto.sct_sub_ll @ setfr.sct_sub_tl
      newto.sct_cst_tot @ setfr.sct_cst_tot WITH STREAM-IO /*GUI*/ .
   down 1.

   display
      getTermLabel("%_CHANGE",8) @ fromset WITH STREAM-IO /*GUI*/ .
   if mtl_pct > - 100000 and mtl_pct < 100000
   then
      display
         mtl_pct format "->>>,>>>,>>9.9%"
         @ setfr.sct_mtl_tl WITH STREAM-IO /*GUI*/ .
   else
   if (newto.sct_mtl_tl + newto.sct_mtl_ll)
    - (oldto.sct_mtl_tl + oldto.sct_mtl_ll) = 0
   then
      display
         glxcst format "->>>,>>>,>>9.9%"
         @ setfr.sct_mtl_tl WITH STREAM-IO /*GUI*/ .
   else
      display
         curcst format ">>>>,>>>,>>9+ %"
         @ setfr.sct_mtl_tl WITH STREAM-IO /*GUI*/ .

   if lbr_pct > - 100000 and lbr_pct < 100000
   then
      display
         lbr_pct format "->>>,>>>,>>9.9%"
         @ setfr.sct_lbr_tl WITH STREAM-IO /*GUI*/ .
   else
   if (newto.sct_lbr_tl + newto.sct_lbr_ll)
    - (oldto.sct_lbr_tl + oldto.sct_lbr_ll) = 0
   then
      display
         glxcst format "->>>,>>>,>>9.9%"
         @ setfr.sct_lbr_tl WITH STREAM-IO /*GUI*/ .
   else
      display
         curcst format ">>>>,>>>,>>9+ %"
         @ setfr.sct_lbr_tl WITH STREAM-IO /*GUI*/ .

   if bdn_pct > - 100000 and bdn_pct < 100000
   then
      display
         bdn_pct format "->>>,>>>,>>9.9%"
         @ setfr.sct_bdn_tl WITH STREAM-IO /*GUI*/ .
   else
   if (newto.sct_bdn_tl + newto.sct_bdn_ll)
    - (oldto.sct_bdn_tl + oldto.sct_bdn_ll) = 0
   then
      display
         glxcst format "->>>,>>>,>>9.9%"
         @ setfr.sct_bdn_tl WITH STREAM-IO /*GUI*/ .
   else
      display
         curcst format ">>>>,>>>,>>9+ %"
         @ setfr.sct_bdn_tl WITH STREAM-IO /*GUI*/ .

   if ovh_pct > - 100000 and ovh_pct < 100000
   then
      display
         ovh_pct format "->>>,>>>,>>9.9%"
         @ setfr.sct_ovh_tl WITH STREAM-IO /*GUI*/ .
   else
   if (newto.sct_ovh_tl + newto.sct_ovh_ll)
    - (oldto.sct_ovh_tl + oldto.sct_ovh_ll) = 0
   then
      display
         glxcst format "->>>,>>>,>>9.9%"
         @ setfr.sct_ovh_tl WITH STREAM-IO /*GUI*/ .
   else
      display
         curcst format ">>>>,>>>,>>9+ %"
         @ setfr.sct_ovh_tl WITH STREAM-IO /*GUI*/ .

   if sub_pct > - 100000 and sub_pct < 100000
   then
      display
         sub_pct format "->>>,>>>,>>9.9%"
         @ setfr.sct_sub_tl WITH STREAM-IO /*GUI*/ .
   else
   if (newto.sct_sub_tl + newto.sct_sub_ll)
    - (oldto.sct_sub_tl + oldto.sct_sub_ll) = 0
   then
      display
         glxcst format "->>>,>>>,>>9.9%"
         @ setfr.sct_sub_tl WITH STREAM-IO /*GUI*/ .
   else
      display
         curcst format ">>>>,>>>,>>9+ %"
         @ setfr.sct_sub_tl WITH STREAM-IO /*GUI*/ .

   if tot_pct > - 100000 and tot_pct < 100000
   then
      display
         tot_pct format "->>>,>>>,>>9.9%"
         @ setfr.sct_cst_tot WITH STREAM-IO /*GUI*/ .
   else
   if (newto.sct_cst_tot - oldto.sct_cst_tot) = 0
   then
      display
         glxcst format "->>>,>>>,>>9.9%"
         @ setfr.sct_cst_tot WITH STREAM-IO /*GUI*/ .
   else
      display
         curcst format ">>>>,>>>,>>9+ %"
         @ setfr.sct_cst_tot WITH STREAM-IO /*GUI*/ .

   down 1.
   display
      "GL" when (tocsgl) @ pt_um
      getTermLabel("AMOUNT_CHANGE",8) @ fromset
      (newto.sct_mtl_tl + newto.sct_mtl_ll)
      - (oldto.sct_mtl_tl + oldto.sct_mtl_ll)
      @ setfr.sct_mtl_tl
      (newto.sct_lbr_tl + newto.sct_lbr_ll)
      - (oldto.sct_lbr_tl + oldto.sct_lbr_ll)
      @ setfr.sct_lbr_tl
      (newto.sct_bdn_tl + newto.sct_bdn_ll)
      - (oldto.sct_bdn_tl + oldto.sct_bdn_ll)
      @ setfr.sct_bdn_tl
      (newto.sct_ovh_tl + newto.sct_ovh_ll)
      - (oldto.sct_ovh_tl + oldto.sct_ovh_ll)
      @ setfr.sct_ovh_tl
      (newto.sct_sub_tl + newto.sct_sub_ll)
      - (oldto.sct_sub_tl + oldto.sct_sub_ll)
      @ setfr.sct_sub_tl
      (newto.sct_cst_tot - oldto.sct_cst_tot)
      @ setfr.sct_cst_tot WITH STREAM-IO /*GUI*/ .

   if line-counter + 6 > page-size then page.
   else down 1.

   /* DELETE NEWLY INACTIVE ELEMENTS FROM SPT_DET      */

   for each spt_det
      fields(spt_site spt_sim spt_part spt_element)
       where spt_site = site1
         and spt_sim  = toset
         and spt_part = pt_part
      no-lock:

      find first newspt
         where newspt.spt_element = spt_det.spt_element
         no-error.

      if not available newspt then do:
         find del-spt_det where
            recid(del-spt_det) = recid(spt_det)
         exclusive-lock no-error.

         if available(del-spt_det) then
            delete del-spt_det.
      end.
   end.

   assign
      oldto.sct_user1  = setfr.sct_user1
      oldto.sct_user2  = setfr.sct_user2
      oldcst           = oldto.sct_cst_tot
      oldto.sct_mtl_tl = 0
      oldto.sct_mtl_ll = 0
      oldto.sct_lbr_tl = 0
      oldto.sct_lbr_ll = 0
      oldto.sct_bdn_tl = 0
      oldto.sct_bdn_ll = 0
      oldto.sct_ovh_tl = 0
      oldto.sct_ovh_ll = 0
      oldto.sct_sub_tl = 0
      oldto.sct_sub_ll = 0.

   /* UPDATE - OR CREATE - ACTIVE ELEMENTS IN SPT_DET     */

   for each newspt exclusive-lock:

      find first ttsc_mstr
         where ttsc_mstr.sc_sim = newspt.spt_sim
         and ttsc_mstr.sc_element = newspt.spt_element
      no-lock no-error.

      if not available ttsc_mstr then do:

         for first scmstr
            fields (sc_category sc_desc sc_element sc_sim)
            where scmstr.sc_sim = fromset and
            scmstr.sc_element = newspt.spt_element no-lock:
         end.

         create sc_mstr.
         assign
            sc_mstr.sc_sim = toset
            sc_mstr.sc_element = newspt.spt_element
            sc_mstr.sc_category = scmstr.sc_category
            sc_mstr.sc_desc = scmstr.sc_desc.
         create ttsc_mstr.
         buffer-copy sc_mstr to ttsc_mstr.

      end.

      find spt_det
      exclusive-lock
         where spt_det.spt_site = newspt.spt_site
         and   spt_det.spt_sim = newspt.spt_sim
         and   spt_det.spt_part = newspt.spt_part
         and   spt_det.spt_element = newspt.spt_element no-error.
      if not available spt_det
      then do:
         create spt_det.
         assign
            spt_det.spt_site = newspt.spt_site
            spt_det.spt_sim = newspt.spt_sim
            spt_det.spt_part = newspt.spt_part
            spt_det.spt_element = newspt.spt_element.

      end.
      assign
         spt_det.spt_ao       = newspt.spt_ao
         spt_det.spt_cst_ll   = newspt.spt_cst_ll
         spt_det.spt_cst_tl   = newspt.spt_cst_tl
         spt_det.spt_element  = newspt.spt_element
         spt_det.spt_mod_date = newspt.spt_mod_date
         spt_det.spt_pct_ll   = newspt.spt_pct_ll
         spt_det.spt_pct_tl   = newspt.spt_pct_tl
         spt_det.spt_userid   = newspt.spt_userid.
     if recid(spt_det) = -1 then .
     if integer(spt_det.spt_pct_ll) = 1 then
         assign
            oldto.sct_mtl_tl = oldto.sct_mtl_tl + spt_det.spt_cst_tl
            oldto.sct_mtl_ll = oldto.sct_mtl_ll + spt_det.spt_cst_ll.

      else if integer(spt_det.spt_pct_ll) = 2 then
         assign
            oldto.sct_lbr_tl = oldto.sct_lbr_tl + spt_det.spt_cst_tl
            oldto.sct_lbr_ll = oldto.sct_lbr_ll + spt_det.spt_cst_ll.

      else if integer(spt_det.spt_pct_ll) = 3 then
         assign
            oldto.sct_bdn_tl = oldto.sct_bdn_tl + spt_det.spt_cst_tl
            oldto.sct_bdn_ll = oldto.sct_bdn_ll + spt_det.spt_cst_ll.

      else if integer(spt_det.spt_pct_ll) = 4 then
         assign
            oldto.sct_ovh_tl = oldto.sct_ovh_tl + spt_det.spt_cst_tl
            oldto.sct_ovh_ll = oldto.sct_ovh_ll + spt_det.spt_cst_ll.

      else if integer(spt_det.spt_pct_ll) = 5 then
         assign
            oldto.sct_sub_tl = oldto.sct_sub_tl + spt_det.spt_cst_tl
            oldto.sct_sub_ll = oldto.sct_sub_ll + spt_det.spt_cst_ll.

      assign
         oldto.sct_user1  = setfr.sct_user1
         oldto.sct_user2  = setfr.sct_user2.

      delete newspt.
   end. /* newspt */

   assign
      oldto.sct_cst_date = today
      oldto.sct_cst_tot = oldto.sct_mtl_tl + oldto.sct_mtl_ll
                        + oldto.sct_lbr_tl + oldto.sct_lbr_ll
                        + oldto.sct_bdn_tl + oldto.sct_bdn_ll
                        + oldto.sct_ovh_tl + oldto.sct_ovh_ll
                        + oldto.sct_sub_tl + oldto.sct_sub_ll.

   if oldcst <> oldto.sct_cst_tot then do:

      find first ttin_mstr where ttin_mstr.in_part = pt_part
      no-lock no-error.

      if available ttin_mstr then do:

         /*MAKE SURE THAT IN_MSTR COST SETS MATCH SI_MSTR SETS*/
         if available pt_mstr then do:
            {gprun.i 'csinsi.p'
               "(input si_cur_set,
                 input si_gl_set,
                 input ttin_mstr.in_part,
                 input ttin_mstr.in_cur_set,
                 input ttin_mstr.in_gl_set,
                 input ttin_mstr.in_site,
                 input icc_gl_set,
                 input icc_cogs,
                 input icc_gl_sum,
                 input icc_gl_tran,
                 input icc_mirror,
                 input icc_jrnl,
                 input rndmthd,
                 input pt_part,
                 input pt_prod_line,
                 input pt_site,
                 input pt_um)"
               }
         end.

         /* CST-ADJ SHOULD NOT BE CREATED FOR ITEMS AT THIS SITE */
         /* THAT ARE LINKED TO ANOTHER SITE FOR GL COSTS.        */
         /* CREATE CST-ADJ ONLY FOR SOURCE SITES i.e. IN_SITE =  */
         /* IN_GL_COST_SITE.                                     */

         if ((ttin_mstr.in_gl_set = oldto.sct_sim or
            (oldto.sct_sim = icc_gl_set and ttin_mstr.in_gl_set = ""))
            and (ttin_mstr.in_site = ttin_mstr.in_gl_cost_site))
         then do:
            trmsg = 5224.

            /*DE-COUPLE PROGRAMS FOR OBJECTS*/

            {gprun.i 'iccstinv.p'
               "(input oldcst,
                 buffer oldto,
                 input 'CCHG',
                 input ttin_mstr.in_site,
                 input icc_cogs,
                 input icc_gl_sum,
                 input icc_gl_tran,
                 input icc_mirror,
                 input icc_jrnl,
                 input rndmthd,
                 input pt_part,
                 input pt_prod_line,
                 input pt_site,
                 input pt_um)"
               }

         end.
      end.
   end.
   
/*GUI*/ {mfguichk.i  &warn=false} /*Replace mfrpchk*/


end. /*copyloop*/
